﻿@using QLNS
@{
    ViewBag.Title = "Add";
    Layout = "~/Views/Shared/_Home.cshtml";
}

@{
    
    List<SelectListItem> selectListIDPhuCap = new List<SelectListItem>();
    List<PhuCap> idll = ViewBag.DSPhuCap;
    foreach (var l in idll)
    {
        SelectListItem item = new SelectListItem();
        item.Text = l.Ten;
        item.Value = l.ID.ToString();
        selectListIDPhuCap.Add(item);
    }
    List<SelectListItem> selectListIDLoaiPhuCap = new List<SelectListItem>();
    List<tblLoaiPhuCap> idLoaiPhuCap = ViewBag.DSLoaiPhuCap;
    foreach(var l in idLoaiPhuCap){
        SelectListItem item = new SelectListItem();
        item.Text = l.TenLoaiPhuCap;
        item.Value = l.Id.ToString();
        selectListIDLoaiPhuCap.Add(item);
    }
} 


@using (Html.BeginForm("Add", "AlloDet", FormMethod.Post, new { name = "form", id = "submit" }))
 { 
    <div class="toolbar">
        <ul>
            <li><input class="tbtnBack" type="button" value="Quay về" onclick="javascript:history.back();return false;"/>
            </li>
            <li><input class="tbtnSave" type="Submit" value="Lưu" /> 
            </li>
        </ul>
        <div class="ttitle">Thêm mới Hồ sơ</div>
    </div>
    <table width="500" border="1">
    <tr>
     
        <td>Loại Phụ cấp </td>
    <td>@Html.DropDownList("IDLoaiPhuCap", selectListIDLoaiPhuCap)</td>
  </tr>
     <tr>
     
        <td>Phụ cấp </td>
    <td>@Html.DropDownList("IDPhuCap", selectListIDPhuCap)</td>
  </tr>
  
</table>
<input type="hidden" name="IDCanBo" value="@ViewBag.Id" />
        <input id="botton" type="Submit" value="Lưu" class="btnSave"/>
 }
 <script type="text/javascript">
     $('#IDLoaiPhuCap').change(function () {
         var idLoaiPhuCap = $('#IDLoaiPhuCap').val();
         $.getJSON("/AlloDet/GetDanhSachPhuCap/" + idLoaiPhuCap, null,
                            function (data) {
                                var select = $('#IDPhuCap');
                                select.empty();
                                select.append($('<option/>', {
                                    value: 0,
                                    text: "Chọn phụ cấp"
                                }));
                                $.each(data, function (index, itemData) {
                                    select.append($('<option/>', {
                                        value: itemData.Key,
                                        text: itemData.Value
                                    }));
                                });
                            });
     });
</script>
